import axios from "axios"


const instance = axios.create({
  timeout: 50000,
})

// 添加请求拦截器
instance.interceptors.request.use(
  config => config,
  error => {
    return Promise.reject(error);
  });

// 添加响应拦截器
instance.interceptors.response.use(response => {
  // const { code, success, msg, data } = response.data
  // if (!success) {
  //   // Message.error(msg)
  // }
  // if (code === -1) {
  //   // token 过期，请求错误等统一处理
  // }
  // data === null ? data = undefined : null
  return response;
}, error => {
  return Promise.reject(error);
});


function MeterAPi(config = {}) {
  const { url = '', method = 'get', params = {}, data = undefined, headers = {} } = config
  instance({ url, method, params, data, ...config })
}

export { instance }
export default MeterAPi
